window.onload = function onLoad ()
{
    // var canvas = document.getElementById("canvas");
    var canvas = document.getElementById( "gl-canvas" );
    var gl = WebGLUtils.setupWebGL( canvas );

    //var gl = canvas.getContext("experimental-webgl");

    console.log("开心啊");
    var program = initShaders( gl, "node-vertex-shader", "node-fragment-shader" );

    gl.useProgram(program);
    //var vertexShaderNode = createShaderFromScriptElement(gl, "node-vertex-shader");

    //var fragmentShaderNode = createShaderFromScriptElement(gl, "node-fragment-shader");
    //var programNode = createProgram(gl, [vertexShaderNode, fragmentShaderNode]);
    //gl.useProgram(programNode);


    var ATTRIBUTES = 5;
    var j = 0;
    var data = [];
    var circle = {x: 100 , y: 100, r: 50};

    data[j++] = (circle.x - circle.r);
    data[j++] = (circle.y - circle.r);
    data[j++] = circle.x;
    data[j++] = circle.y;
    data[j++] = circle.r;

    data[j++] = (circle.x + (1 + Math.sqrt(2)) * circle.r);
    data[j++] = circle.y - circle.r;
    data[j++] = circle.x;
    data[j++] = circle.y;
    data[j++] = circle.r;

    data[j++] = (circle.x - circle.r);
    data[j++] = (circle.y + (1 + Math.sqrt(2)) * circle.r);
    data[j++] = circle.x;
    data[j++] = circle.y;
    data[j++] = circle.r;

    console.log(data);
    var dataBuffer = new Float32Array(data);

    var buffer = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
    gl.bufferData(
        gl.ARRAY_BUFFER, 
        dataBuffer,
        gl.STATIC_DRAW);

    var resolutionLocation = gl.getUniformLocation(program, "u_resolution");
    gl.uniform2f(resolutionLocation, canvas.width, canvas.height);

    var positionLocation = gl.getAttribLocation(program, "a_position");
    var centerLocation = gl.getAttribLocation(program, "a_center");
    var radiusLocation = gl.getAttribLocation(program, "a_radius");


    gl.enableVertexAttribArray(positionLocation);
    gl.enableVertexAttribArray(centerLocation);
    gl.enableVertexAttribArray(radiusLocation);

    gl.vertexAttribPointer(positionLocation, 2, gl.FLOAT, false, ATTRIBUTES * Float32Array.BYTES_PER_ELEMENT, 0);
    gl.vertexAttribPointer(centerLocation, 2, gl.FLOAT, false, ATTRIBUTES * Float32Array.BYTES_PER_ELEMENT, 8);
    gl.vertexAttribPointer(radiusLocation, 1, gl.FLOAT, false, ATTRIBUTES * Float32Array.BYTES_PER_ELEMENT, 16);

    gl.drawArrays(gl.TRIANGLES, 0, data.length/ATTRIBUTES);
};
//onLoad();
